package com.cpumonitor;

import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        //System.out.println(Utils.getLinuxProcessorCount());
        /*CpuMonitor cpuMonitor = new CpuMonitor();
        CpuTotalInfo cpuTotalInfo = cpuMonitor.getprocessInfors();
        CpuTotalLinuxInfo cpuTotalLinuxInfo = (CpuTotalLinuxInfo)cpuTotalInfo;
        //System.out.println(cpuTotalLinuxInfo.getProcessLinuxInfos());
        for(int i=0;i<cpuTotalLinuxInfo.getProcessLinuxInfos().size();i++){
            System.out.println(cpuTotalLinuxInfo.getProcessLinuxInfos().get(i).getCommand());
        }*/
/*        String procCmd = "top -b -n 1";
        Process process;
        InputStreamReader ir;
        BufferedReader input;
        StringBuffer sb = new StringBuffer();
       String line=null;

        process =  Runtime.getRuntime().exec(procCmd);
        ir = new InputStreamReader(process.getInputStream());
        input = new BufferedReader(ir);
        while((line = input.readLine())!=null){
            //System.out.println(line);
            //sb.append(line+System.lineSeparator());
            if(line.startsWith("%Cpu")){
               System.out.println(line);
                String keys_str[] = line.trim().split("[a-zA-Z%,:()\\s]+");
                for(int i=0;i<keys_str.length;i++){
                    System.out.println("="+keys_str[i]);
                    //String key = keys_str[i].trim().split("\\s")[0];
                }
            }
            if(line.startsWith("  PID"))continue;
            if(line.startsWith(" ")){
                //System.out.println(line);
                String values_str[] = line.trim().split("\\s+");
                if(12 == values_str.length){
                    for(int i=0;i<values_str.length;i++){
                        System.out.println("="+values_str[i]);
                    }
                    break;

                }
            }
            //System.out.println();
        }*/
        //System.out.println(sb);
        CpuMonitor cpuMonitor = new CpuMonitor();
        CpuTotalInfo cpuTotalInfo = cpuMonitor.getCpuInfors();
        CpuTotalLinuxInfo cpuTotalLinuxInfo = (CpuTotalLinuxInfo)cpuTotalInfo;
        for(int i = 0; i< cpuTotalLinuxInfo.getProcessLinuxInfos().size(); i++){
           System.out.println(cpuTotalLinuxInfo.getProcessLinuxInfos().get(i).getCommand());
        }
        System.out.println(cpuTotalLinuxInfo.getUs());
    }
}
